﻿namespace Luka;

/// <summary>
/// 基本验证码操作类
/// </summary>
public sealed class CaptchaExtensions
{
    /// <summary>
    /// 文本
    /// </summary>
    private const string Chars = "1,2,3,4,5,6,7,8,9,0,A,a,B,b,C,c,D,d,E,e,F,f,G,g,H,h,J,j,K,k,L,l,M,m,N,n,P,p,Q,q,R,r,S,s,T,t,U,u,V,v,W,w,X,x,Y,y,Z,z";

    /// <summary>
    /// 随机文本(含数字)
    /// </summary>
    /// <param name="length">长度</param>
    /// <returns></returns>
    public static string GetRandomText(int length = 6)
    {
        var random = new Random();
        char[] captchaChars = new char[length];
        for (int i = 0; i < captchaChars.Length; i++)
        {
            captchaChars[i] = Chars[random.Next(Chars.Length)];
        }
        return new string(captchaChars);
    }

    /// <summary>
    /// 随机数字
    /// </summary>
    /// <param name="length">长度</param>
    /// <returns></returns>
    public static string GetRandomNum(int length = 6)
    {
        var random = new Random();
        char[] captchaChars = new char[length];
        for (int i = 0; i < captchaChars.Length; i++)
        {
            captchaChars[i] = Chars[random.Next(10)];
        }
        return new string(captchaChars);
    }
}